package com.yang.testservletcontext;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/tsc01")
public class TestServletContext01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        获取servletcontext的四种方法。
//        1  (推荐)
        ServletContext context01 = req.getServletContext();
//        2
//        ServletContext context02 = req.getSession().getServletContext();
//        3
//        ServletContext context03 = getServletConfig().getServletContext();
//        4
//        ServletContext context04 = getServletContext();
//        地址
        String path = context01.getRealPath("/");
        System.out.println(path);
//        版本
        String info = context01.getServerInfo();
        System.out.println(info);
    }
}
